{include file="public/header" /}
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>数据库表列表</h5> &nbsp;&nbsp; <span> (备份文件数量：{$filenum}，占空间大小：{$total|format_bytes})</span>
                    <div class="ibox-tools">
                        <a class="collapse-link" href="javascript:location.replace(location.href);">
                            <i class="glyphicon glyphicon-refresh"></i>
                        </a>
                    </div>
                </div>
                <div class="ibox-content">
                    <div class="row">
                        <div class="col-sm-6">
                            <!--操作栏-->
                            <form class="form-inline" action="{:U('restoreUpload')}" name="change_System" method="post" enctype="multipart/form-data">
                                <div class="form-group">
                                    <input type="file" class="btn" name="sqlfile"></div>
                                <div class="form-group">
                                    <input type="submit" value="上传并执行sql文件">
                                </div>
                            </form>
                        </div>
                    </div>
                    <div class="table-responsive">
                        <table class="table table-striped table-hover">
                            <thead>
                            <!--表格头部-->
                            <tr>
                                <!--变化列-->
                                <th>文件名称</th>
                                <th>卷号</th>
                                <th>压缩</th>
                                <th>数据大小</th>
                                <th>备份时间</th>
                                <th>状态</th>
                                <!--变化列-->

                                <th>操作</th>
                            </tr>
                            <!--/表格头部-->
                            </thead>
                            <tbody id="pageView">
                            {foreach $list as $vo}
                            <tr>
                                <td>{$vo.basename}</td>
                                <td>{$vo.part}</td>
                                <td>{$vo.compress}</td>
                                <td>{$vo.size|format_bytes}</td>
                                <td>{$vo.time|date="Y-m-d H:i:s",###}</td>
                                <td class="msg">-</td>
                                <td>
                                    <a title="恢复" href="{:U('import',array('time'=>$vo['time']))}"><i
                                            class="fa fa-repeat text-muted"></i></a>&nbsp;
                                    <a title="下载" href="{:U('downFile',array('time'=>$vo['time']))}"><i
                                            class="fa fa-download text-muted"></i></a>&nbsp;
                                    <a title="删除" href="{:U('del?time='.$vo['time'])}"><i
                                            class="fa fa-trash text-muted"></i></a>
                                </td>
                            </tr>
                            {/foreach}
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
{include file="public/footer" /}
<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript">
    $(document).ready(function () {
        //设置选项框样式
        setIcheck();
    });

    (function ($) {
        var $export = $("#export"), tables
        $export.click(function () {
            //批量删除 获取选中id数组
            var chk_value = [];
            $('input[name="id"]:checked').each(function () {
                chk_value.push($(this).val());
            });

            if (chk_value == undefined || chk_value == '') {
                swal("请先选择数据！", "", "error");
                return;
            }

            $export.addClass("disabled");
            $export.html("正在发送备份请求...");
            $.post(
                "export",
                {tables: chk_value},
                function (data) {
                    if (data.status) {
                        tables = data.tables;
                        $export.html(data.info + "开始备份，请不要关闭本页面！");
                        backup(data.tab);
                        window.onbeforeunload = function () {
                            return "正在备份数据库，请不要关闭！"
                        }
                    } else {
                        swal("备份出错！", data.info, "error");
                        $export.removeClass("disabled");
                        $export.html("立即备份");
                    }
                },
                "json"
            );
            return false;
        });

        function backup(tab, status) {
            status && showmsg(tab.id, "开始备份...(0%)");
            $.get("export", tab, function (data) {
                if (data.status) {
                    showmsg(tab.id, data.info);
                    if (!$.isPlainObject(data.tab)) {
                        $export.removeClass("disabled");
                        $export.html("备份完成，点击重新备份");
                        window.onbeforeunload = function () {
                            return null
                        }
                        return;
                    }
                    backup(data.tab, tab.id != data.tab.id);
                } else {
                    $export.removeClass("disabled");
                    $export.html("立即备份");
                }
            }, "json");
        }

        function showmsg(id, msg) {
            console.log(tables[id] + msg);
            $("#pageView").find("input[value=" + tables[id] + "]").closest("tr").find(".msg").html(msg);
        }
    })(jQuery);
</script>
<!--/请在上方写此页面业务相关的脚本-->
